Skip to content

Apply except as a regex to YAML, and merge relocated sections - #1108

Draft
timtebeek wants to merge 2 commits into
mainfrom
tim/albuquerque-v4
Draft

Apply except as a regex to YAML, and merge relocated sections#1108
timtebeek wants to merge 2 commits into
mainfrom
tim/albuquerque-v4

Conversation

@timtebeek

@timtebeek timtebeek commented Jul 29, 2026

Copy link
Copy Markdown
Member

What's changed?

Two separate defects kept logging.file from surviving UpgradeSpringBoot_2_2 in YAML, and left the recipe non-idempotent:

  • 1. except was a regex for properties but a glob for YAML. The option is documented as "Regex", and ChangeSpringPropertyKey builds a real regex for the properties path, but it hands the same list straight to org.openrewrite.yaml.ChangePropertyKey, which matches it as a glob. So except: [ .+ ] — the way spring-boot-22-properties.yml says "only rename logging.file when it is a leaf" — excluded nothing at all in YAML, and a logging.file mapping got buried under logging.file.name. The regex is now resolved against the subkeys actually present under the old key, and those literal subkeys are passed on to the YAML recipe, so both formats exclude the same subproperties. This is the mismatch @nmck257 called out on #581.

2. Relocating a property into a section that already exists produced a duplicate key. logging.pathlogging.file.path appended a second file: entry next to the existing one, and the next cycle then renamed the property again — so the recipe never converged. Duplicate entries are now merged back together, limited to the segments of the new key so unrelated duplicates elsewhere in the file are left alone.

# before
logging:
  file:
    max-history: 10
    max-size: 10MB
  level:
    org: INFO
  path: ${user.home}/some-folder

# after (before this PR, and still changing on the next cycle)
logging:
  file:
    name:
      max-history: 10
      max-size: 10MB
  level:
    org: INFO
  file:
    name:
      path: ${user.home}/some-folder

# after (this PR)
logging:
  file:
    max-history: 10
    max-size: 10MB
    path: ${user.home}/some-folder
  level:
    org: INFO

ChangeSpringPropertyKeyTest#loggingFileSubpropertiesYaml — replicated in feb28d5 back in 2023 and @Disabled ever since — is enabled and passes. Two smaller tests pin each half of the fix on its own.

Anything in particular you'd like reviewers to focus on?

MergeRelocatedSectionsVisitor deliberately does not reuse org.openrewrite.yaml.MergeDuplicateSectionsVisitor: that one treats any non-newline entry prefix as a comment and bails, so it never merges anything indented, which is every case here. This visitor skips entries whose prefix actually contains a # instead.

excludedSubkeys only inspects direct children of a mapping spelled out under the old key, matching how the except option is documented. A file that writes the old key in flattened form (logging.file.max-size: 10MB) is unchanged in behaviour by this PR.

Related issues this does not close

`ChangeSpringPropertyKey` documents `except` as a regex and applies it as
one to properties files, but `org.openrewrite.yaml.ChangePropertyKey`
matches it as a glob, so `except: [ .+ ]` silently excluded nothing in
YAML. Resolve the regex against the subkeys actually present under the
old key, and pass those literal subkeys on to the YAML recipe.

Relocating a property into a section that already exists also left two
mapping entries with the same key, which made the recipe non-idempotent;
merge those back together, limited to the segments of the new key.

Fixes #436
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

spring-boot-22 Recipe messes up logging.file.* in application.yaml

1 participant